package com.wbcs.system.function;

import com.wbcs.config.Config;
import com.wbcs.util.Tools;

import java.util.HashMap;
import java.util.Map;

public abstract class AbsFunc implements IFunc{

    protected String funcName;
    protected Map<String, IFunc> mInnerFunc = new HashMap<String, IFunc>();
    /**
     * 仅接受执行函数执行动作参数
     * @param does 执行动作字符串数组
     */
    public AbsFunc(String... does){
        //检查does是否为已定义函数，创建内联函数
        for(Map.Entry entry : Config.getInstance().getmReportFunc().entrySet())
        {
            Object name = entry.getKey();
            for (String doitem: does)
            {
                if(Tools.isEmpty(doitem, true))continue;
                if(doitem.indexOf(")") == -1 ||  doitem.indexOf("(") == -1) continue;

                String funcName = Tools.getRgexMatchContent(doitem, "[^()]+");
                if(doitem.equalsIgnoreCase(String.valueOf(funcName)) && !mInnerFunc.containsKey(funcName))
                {//函数执行动作中存在函数注册名称则创建函数对象
                    mInnerFunc.put(funcName, FuncAssistant.getInstance().getHadParamsRequireFunc(doitem));
                }
            }
        }
    }

    @Override
    public String funcName() {
        // TODO Auto-generated method stub
        return funcName;
    }

    @Override
    public IFunc getInnerFunc(String funcName){
        return mInnerFunc.get(funcName);
    }
}
